def run(params:list[str]):
    
    #对话式检索增强生成 (Conversational RAG)
    from ApiBase import apiBase
    from ApiVanna import vanna
    # df_information_schema = vanna.run_sql("SELECT * FROM INFORMATION_SCHEMA.COLUMNS")
    # plan = vanna.get_training_plan_generic(df_information_schema)
    # vanna.train(plan=plan)
    
    ################## sql
    #vanna.train_sql()
    ################## sql-score
    #vanna.train_sql_score()

    vanna.connect_to_postgres()
    question=apiBase.argv(params,1,'''select chatgpt('llmrag_sql','## view\nCREATE OR REPLACE VIEW titleview AS SELECT titles.title, titleauthor.au_ord, authors.au_lname, titles.price, titles.num_sold, titles.pub_id FROM authors JOIN titleauthor ON authors.au_id = titleauthor.au_id JOIN titles ON titles.title_id = titleauthor.title_id;\n## human\nGenerate new SQL statements based on historical records and contextual content') as code''')
    try:
        #print(f"question={question}\n")
        sql = vanna.generate_sql(question=question)
        #print(f"sql={sql}\n")
        #sql="select llmgencode('function','add_numbers;v_num1 integer, v_num2 integer') as code;"    
        result=vanna.run_sql(sql)
        return result.to_json()        
    except Exception as e:
        return f"function error:{e}"        